Fix: prevent prototype pollution by validating dynamic keys across controllers #6655
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Fix: Replace unsafe object keys with validations or safe structures (
Map/Object.create(null))This pull request addresses multiple prototype pollution vulnerabilities across different controllers in the
MetaMask/core. The root cause in all cases was the usage of untrusted dynamic keys (chainId,namespace, etc.) on plain JavaScript objects, which could allow pollution via special keys like__proto__,constructor, orprototype.Changes Implemented
1. AccountTrackerController.ts (
updateNativeBalances,updateStakedBalances)Added guard checks inside iteration loops to skip dangerous keys:
"__proto__""constructor""prototype"Prevents updates to polluted object prototypes.
2. TokenBalancesController.ts
chainIdkeys in loops around lines 596–632.continue.3. earn-controller/selectors.ts
Mapfor storingprotocol → id → LendingMarketmappings.selectLendingMarketsByProtocolAndId,selectLendingMarketForProtocolAndId) to use.get()instead of unsafe property access.Mapusage.4. EnsController.ts (
deletemethod)delete state.ensEntries[chainId][normalizedEnsName].__proto__, etc.) are never used for deletion operations.5. NameController.ts (
#updateEntry)Replaced
{}object instantiations withObject.create(null)for:state.namestypeEntriesvariationEntriesEnsures prototype-less storage to prevent pollution.
6. NetworkEnablementController.ts (
enableNetworkInNamespace)namespacematches a forbidden key (__proto__,constructor,prototype), an Error is thrown and the update is rejected.7. sample-petnames-controller.ts (
assignPetname)chainIdequals__proto__,constructor, orprototype.Notes
Mapwas infeasible, localized guards were added for defense-in-depth.Checklist